import java.awt.Color;
import java.awt.geom.Line2D;
import java.awt.geom.Path2D;
import java.awt.geom.Point2D;
import java.io.BufferedReader;
import java.io.IOException;
/**
 * 
 * @author Adam and Terry
 *
 */
public class Rail {
	
	private static final long serialVersionUID = 741713763308816772L;
	private String name;
	private String delimiter;
	private boolean changed;
	private Color colour; 
	private static int count =0;
	private Path2D.Double drawPath;

	
	/**
	 * 
	 * @param name
	 * @param delimiter
	 */
	public Rail(String name, String delimiter) {
		this.name = name;
		
		this.changed = false;
		this.delimiter = delimiter; 
		this.colour = Color.GRAY;
		this.drawPath = new Path2D.Double();
	
		
	}
	
	public Path2D.Double getDrawPath()
	{
		return this.drawPath;
	}
	
	
	/**
	 * 
	 * @return the name of the rail 
	 */

	public String getName() {
		return this.name;
	}
	
	public void setName(String name)
	{
		this.name = name;
	}
	
	public boolean getChanged()
	{
		return this.changed; 
	}
	
	
	public void setChanged(boolean changed)
	{
		this.changed = changed; 
	}
	
	/**
	 * 
	 * @return the colour of the rail 
	 */
	public Color getColour(){
		return colour;
	}
	
	/**
	 * Reads lon-lat data. Stops when line "END" is read.
	 * 
	 * @param input
	 *            open file which has just read the number
	 * @throws IoException
	 *             or subclass if something goes wrong
	 */
	public void read(BufferedReader input, String line) throws IOException {
		
		Point2D.Double current;
		Point2D.Double prev = null;

		while (!line.trim().equalsIgnoreCase("end")) {
			
		
			String[] parts = line.split(this.delimiter);
			
			//System.out.println(parts.length);
			
			if(parts.length > 1){
		
			
			
			if(parts.length == 5)
			{
				
			}
			if(parts.length == 3 ) 
			{

				double x = java.lang.Double.parseDouble(parts[1]);
				double y = java.lang.Double.parseDouble(parts[2]);
				current = new Point2D.Double(x, y);
		
				if (prev != null) {			
					drawPath.append(new Line2D.Double(current.x, current.y, prev.x, prev.y), true);
				}
				
				prev = current;
			}
			
			line = input.readLine();
			}
		}
		
		
	}
}